package com.homework.work04;

/**
 * 求n个整数的和，至少传入一个参数
 */
public class SumDemo {
    //1.只可以有一个可变参数而且必须在最后
    int sum(int number,int... args) {
        int sum = 0;
        sum+=number;
        if(args.length>0) {
            for(int i=0;i<args.length;i++) {
                sum+=args[i];
            }
        }
        return sum;
    }
    public static void main(String[] args) {
        SumDemo sumDemo = new SumDemo();
        int result = sumDemo.sum(1,2,3);
        System.out.println(result);
    }
}
